package com.game.spacetrader;
import java.io.Serializable;
import java.util.*;

import com.game.spacetrader.TradeGoods.TradeGoods;
import com.game.spacetrader.TradeGoods.TradeGoodsAdaptor;
import com.game.spacetrader.map.Coordinates;

/**
 * Class that represents the player
 *
 */
public class Player implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int pilot, fighter, trader, engineer,maxCargo,cargoSize;
	private String name;
	private int points;
	private Coordinates location; //TODO change this to planet.
	private Ship ship;
	private ArrayList<TradeGoods> cargo; //TODO create it as initial cargo
	private int gas;

	/**
	 * Constructor
	 * @param name name of player
	 * @param p pilot skill
	 * @param f fighter skill
	 * @param t trader skill
	 * @param e engineer skill
	 * @param loc location
	 * @param ship ship 
	 */
	public Player(String name, int p, int f, int t, int e, Coordinates loc,Ship ship){
		setName(name);
		setPilot(p);
		setFighter(f);
		setTrader(t);
		setEngineer(t);
		setPoints(1000);
		setShip(ship);
		cargo = TradeGoodsAdaptor.getCargo();
		maxCargo = ship.getCargoHolds();
		location=loc;
		cargoSize=0;
		gas=100;
	}
	
	/**
	 * Constructor
	 * @param name name of player
	 * @param p pilot skill
	 * @param f fighter skill
	 * @param t trader skill
	 * @param e engineer skill
	 */
	public Player(String name, int p, int f, int t, int e){
		this(name, p, f, t, e, new Coordinates(0,0),new Ship("Gnat",70,14,1,1,15,0,0));
	}
	
	/**
	 * Constructor
	 * @param name name of player
	 */
	public Player(String name){
		this(name, 0,0,0,0);
	}
	public int getMaxCargo() {
		return maxCargo;
	}
	public void setMaxCargo(int maxCargo) {
		this.maxCargo = maxCargo;
	}
	public Player(){
		this("", 0,0,0,0);
	}
	public Ship getShip() {
		return ship;
	}
	public void setShip(Ship ship) {
		this.ship = ship;
	}
	public int getPilot() {
		return pilot;
	}
	public void setPilot(int pilot) {
		this.pilot = pilot;
	}
	public int getFighter() {
		return fighter;
	}
	public void setFighter(int fighter) {
		this.fighter = fighter;
	}
	public int getTrader() {
		return trader;
	}
	public void setTrader(int trader) {
		this.trader = trader;
	}
	public int getEngineer() {
		return engineer;
	}
	public void setEngineer(int engineer) {
		this.engineer = engineer;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getPoints() {
		return points;
	}
	public void setPoints(int points) {
		this.points = points;
	}
	public Coordinates getLocation() {
		return location;
	}
	public void setLocation(Coordinates location) {
		this.location = location;
	}
	public int getCargoSize(){
		return cargoSize;
	}
	public void addCargoSize(int g){
		cargoSize+=g;
	}
	public void subCargoSize(int g){
		cargoSize-=g;
	}
	public ArrayList<TradeGoods> getCargo() {
		return cargo;
	}
	public void setPlanet(Planet p){
		for (TradeGoods t:cargo){
			t.setPlanet(p);
		}
		p.newEvent();
	}
	
	/**
	 * Adds a good to cargo
	 * @param index index of the good
	 * @param add number to add
	 */
	public void addToCargo(int index,int add){
		TradeGoods goods = cargo.get(index);
		int amountHave = goods.getQuantityHave();
		goods.setQuantityHave(amountHave+add);
		cargoSize++;
	}
	public int getGas() {
		return gas;
	}
	public void setGas(int gas) {
		this.gas = gas;
	}
}